<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="rich" uri="http://richfaces.org/rich" %>
<%@ taglib prefix="a4j" uri="http://richfaces.org/a4j" %>


<%--
  Created by IntelliJ IDEA.
  User: Волков Олег
  Date: 07.05.14
  Time: 10:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
</head>
<body>
<f:view>

    <a4j:form>
        <a4j:commandButton value="Выход" action="#{UserAutorisationBean.logout}" oncomplete="document.location='../login'"/>
        <rich:dataTable id="tab1" rows="20" value="#{GoodsBean.model}" width="300" title="Goods" styleClass="full"
                        var="good" rowKeyVar="row" border="2" rendered="true">
            <rich:column>
                    <a4j:commandLink id="deletelink" ajaxSingle="true" onclick="Richfaces.showModalPanel('deletePanel')">
                        <h:graphicImage value="resourses/images/delete.GIF"/>
                        <f:setPropertyActionListener target="#{GoodsBean.currentIndex}" value="#{row}"/>
                        <f:setPropertyActionListener value="#{good}" target="#{GoodsBean.singleGood}"/>
                    </a4j:commandLink>
                    <rich:toolTip for="deletelink" value="#{goodsloc.delete}"/>
                    <a4j:commandLink id="editlink" ajaxSingle="true" onclick="Richfaces.showModalPanel('editPanel')">
                        <h:graphicImage value="resourses/images/edit.GIF"/>
                        <f:setPropertyActionListener value="#{row}" target="#{GoodsBean.currentIndex}"/>
                        <f:setPropertyActionListener value="#{good}" target="#{GoodsBean.singleGood}"/>
                    </a4j:commandLink>
                    <rich:toolTip for="editlink" value="#{goodsloc.edit}"/>
            </rich:column>
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="#{goodsloc.name}"/>
                </f:facet>
                <h:outputText  value="#{good.name}"/>
            </rich:column>
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="#{goodsloc.desc}"/>
                </f:facet>
                <h:outputText value="#{good.description}"/>
            </rich:column>
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="#{goodsloc.price}"/>
                </f:facet>
                <h:outputText value="#{good.price}"/>
            </rich:column>
            <f:facet name="footer">
                <rich:datascroller renderIfSinglePage="false"/>
            </f:facet>
        </rich:dataTable>
        <%--Кнопки взаимодействия с экселем и добавления нового товара--%>
        <h:panelGrid columns="3">
            <a4j:commandButton value="#{goodsloc.excelexport}"
                               action="#{GoodsBean.goUpload}"/>
            <h:commandButton value="#{goodsloc.excelimport}"
                             action="#{GoodsBean.writeExcel}"/>
            <a4j:commandButton value="#{goodsloc.add}"
                               onclick="Richfaces.showModalPanel('editPanel')">
            </a4j:commandButton>
        </h:panelGrid>
    </a4j:form>

    <%-------------Всплывающие окна----------------------------------%>

    <%--Удалить поле--%>

    <rich:modalPanel id="deletePanel" width="200" height="100">
        <f:facet name="header">
            <a4j:outputPanel ajaxRendered="true">
                <h:outputText value="Удалить товар #{GoodsBean.singleGood.name}?"/>
            </a4j:outputPanel>
        </f:facet>
        <h:form>
            <center>
                <h:panelGrid columns="2">
                    <a4j:commandButton rendered="true" value="Да"
                                       action="#{GoodsBean.deleteGood}" reRender="tab1"
                                       oncomplete="Richfaces.hideModalPanel('deletePanel')"/>
                    <h:commandButton value="Нет" action="#{GoodsBean.clearAll}"
                                     onclick="Richfaces.hideModalPanel('deletePanel')"/>
                </h:panelGrid>
            </center>

        </h:form>
    </rich:modalPanel>
    <%--Редактировать поле--%>

    <rich:modalPanel id="editPanel" autosized="true">
        <f:facet name="header">
            <h:outputText value="#{goodsloc.head}"/>
        </f:facet>
        <h:form>
            <a4j:outputPanel ajaxRendered="true">
                <h:panelGrid columns="2">
                    <h:outputText value="#{goodsloc.name}"/>
                    <h:inputText id="name" value="#{GoodsBean.singleGood.name}"
                                 required="true" requiredMessage="#{goodsloc.msgs}"/>
                    <h:outputText value="#{goodsloc.desc}"/>
                    <h:inputText id="desc" value="#{GoodsBean.singleGood.description}"
                                 required="true" requiredMessage="#{goodsloc.msgs}"/>
                    <h:outputText value="#{goodsloc.price}"/>
                    <h:inputText value="#{GoodsBean.singleGood.price}"
                                 required="true" requiredMessage="#{goodsloc.msgs}"/>
                </h:panelGrid>
            </a4j:outputPanel>
            <a4j:commandButton immediate="false" value="Да" action="#{GoodsBean.saveGood}" reRender="tab1"
                               oncomplete="Richfaces.hideModalPanel('editPanel')"/>
            <a4j:commandButton value="Нет" action="#{GoodsBean.clearAll}"
                               onclick="Richfaces.hideModalPanel('editPanel')"/>
        </h:form>
    </rich:modalPanel>
</f:view>
</body>
</html>
